package com.zhoumengjie;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GetJsonServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Person person=new Person("周夕何",18);
//        List<Person> persons=new ArrayList<>();
//        persons.add(person);
//        person=new Person("韩非",18);
//        persons.add(person);
        String personJSON= JSON.toJSONString(person);

        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write(personJSON);
        System.out.println(personJSON);
    }
}

class Person{
    public Person(String name,int age){
        this.name=name;
        this.age=age;
    }

    public String name;
    public int age;

}
